﻿using Microsoft.SharePoint;
using System;
using System.ComponentModel;
using System.Web.UI.WebControls.WebParts;

namespace Portal
{
    [ToolboxItemAttribute(false)]
    public partial class HappinessOfficeDetails : WebPart
    {
        // Uncomment the following SecurityPermission attribute only when doing Performance Profiling on a farm solution
        // using the Instrumentation method, and then remove the SecurityPermission attribute when the code is ready
        // for production. Because the SecurityPermission attribute bypasses the security check for callers of
        // your constructor, it's not recommended for production purposes.
        // [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Assert, UnmanagedCode = true)]
        public HappinessOfficeDetails()
        {
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            InitializeControl();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            SPWeb web = SPContext.Current.Web;
            SPList happinessOfficeList = web.GetList("/Lists/HappinessOffice/");
            SPListItem happinessItem = happinessOfficeList.GetItemById(Convert.ToInt32(Page.Request.Params["ID"]));
            string happinessTitle = happinessItem["Title"].ToString();
            string happinessDescription = happinessItem["Description"].ToString();
            string happinessImage = happinessItem["HappinessImage"].ToString();
            string happinessDate= "On " + Convert.ToDateTime(happinessItem["HappinessDate"].ToString()).ToString("MMM dd, yyyy");

            lblHappinessTitle.Text = happinessTitle;
            lblHappinessDate.Text = happinessDate;
            lblHappinessDescription.Text = happinessDescription;
            imgHappinessImage.ImageUrl = happinessImage.Split(',')[0];
        }
    }
}
